package com.dmz.resold.apartment.config;

import com.dmz.resold.apartment.service.ReHBSendReq;
import com.dmz.resold.apartment.service.SendReqJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lee
 */
@Configuration
public class QuartzConfig {

    @Value("${quartz.cron.send-req-job:*/30 * * * * ?}")
    private String sendReqJobCron;

    @Value("${quartz.cron.re-hb-send-req:0 0/1 * * * ?}")
    private String reHBSendReqCron;

    @Bean
    public JobDetail sendReqJobDetail() {
        return JobBuilder.newJob(SendReqJob.class)
                .withIdentity("SendReqJob", "group1")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger sendReqJobTrigger() {
        return TriggerBuilder.newTrigger()
                .forJob(sendReqJobDetail())
                .withIdentity("SendReqJobTrigger", "group1")
                .withSchedule(CronScheduleBuilder.cronSchedule(sendReqJobCron))
                .build();
    }

    @Bean
    public JobDetail reHBSendReqJobDetail() {
        return JobBuilder.newJob(ReHBSendReq.class)
                .withIdentity("ReHBSendReq", "group1")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger reHBSendReqJobTrigger() {
        return TriggerBuilder.newTrigger()
                .forJob(reHBSendReqJobDetail())
                .withIdentity("ReHBSendReqTrigger", "group1")
                .withSchedule(CronScheduleBuilder.cronSchedule(reHBSendReqCron))
                .build();
    }
}